import { EVENTS } from '../../events';
import type { Condition } from '../../systems/condition-checker/type';
import type { ItemId } from '../item';

export interface NarrayorStoryItem {
  id: string;
  type: 'narrator';
  text: string[];
  next?: string;
}

export interface DialogStoryItem {
  id: string;
  type: 'dialog';
  name: string;
  text: string[];
  next?: string;
}

export interface InventoryAddEventItem {
  cmd: typeof EVENTS.INVENTORY_ADD;
  itemId: ItemId;
  amount: number;
}
export interface WalletDeductSpiritStoneEventItem {
  cmd: typeof EVENTS.WALLET_DEDUCT_SPIRIT_STONE;
  amount: number;
}
export type ChoicesEventItem =
  | InventoryAddEventItem
  | WalletDeductSpiritStoneEventItem;
export interface ChoicesItem {
  text: string;
  next: string;
  events?: ChoicesEventItem[];

  /** 判断条件 */
  condition?: Condition[];
  /** 判断失败后跳转 */
  failNext?: string;
}
export interface ChoiceStoryItem {
  id: string;
  type: 'choice';
  text: string[];
  choices: ChoicesItem[];
}

export type StoryItem = NarrayorStoryItem | DialogStoryItem | ChoiceStoryItem;
export type SuccessEvent =
  | InventoryAddEventItem
  | WalletDeductSpiritStoneEventItem;
export interface SuccessFlag {
  /** 经过哪个节点 */
  nodeId: string;
  /** 有选项的时候添加 */
  choiceIndex: number;
}
export type SuccessCondition =
  | { type: 'visit'; nodeId: string }
  | { type: 'choice'; nodeId: string; choiceIndex: number };
export interface StoryConfig {
  items: StoryItem[];
  successConditions?: SuccessCondition[];
  successEvents?: SuccessEvent[];
}
